//package com.xiaopeng.system.common.handler;
//
//
//import com.alibaba.fastjson2.JSON;
//import com.xiaopeng.system.common.annotation.ResponseWrapper;
//import com.xiaopeng.common.httpResult.enums.HttpResultCodeEnum;
//import com.xiaopeng.common.httpResult.model.HttpResult;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.core.MethodParameter;
//import org.springframework.http.MediaType;
//import org.springframework.http.server.ServerHttpRequest;
//import org.springframework.http.server.ServerHttpResponse;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
//
//
//
//@ControllerAdvice(annotations = ResponseWrapper.class)
//@Slf4j
//public class ResponseResultHandlerAdvice implements ResponseBodyAdvice<Object> {
//
//    @Override
//    public boolean supports(MethodParameter methodParameter, Class converterType) {
//        log.info("returnType:" + methodParameter);
//        log.info("converterType:" + converterType);
//        // response是ResponseDTO类型 不进行包装
//        return !methodParameter.getParameterType().isAssignableFrom(HttpResult.class);
//    }
//
//    @Override
//    public Object beforeBodyWrite(Object body,
//                                  MethodParameter returnType,
//                                  MediaType selectedContentType,
//                                  Class selectedConverterType,
//                                  ServerHttpRequest request,
//                                  ServerHttpResponse response) {
//        // 判断响应的Content-Type为JSON格式的body
//        if (MediaType.APPLICATION_JSON.equals(selectedContentType)) {
//            // 如果响应返回的对象为统一响应体，则直接返回body
//            if (body instanceof HttpResult) {
//                return body;
//            } else {
//                // 只有正常返回的结果才会进入这个判断流程，所以返回正常成功的状态码
//                return new HttpResult(HttpResultCodeEnum.SUCCESS.getCode(),
//                    HttpResultCodeEnum.SUCCESS.getMessage(),
//                    body);
//            }
//        }
//
//        HttpResult responseDTO = new HttpResult(HttpResultCodeEnum.SUCCESS.getCode(),
//                HttpResultCodeEnum.SUCCESS.getMessage(),
//                body);
//        return JSON.toJSONString(responseDTO);
//    }
//
//}
